package com.lxw.framework.exception;

import com.lxw.framework.model.response.CommonCode;
import com.lxw.framework.model.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalException {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult customException(Exception e){
      log.error("catch exception : {}exception:",e.getMessage(), e);
      //控制台打印
      e.printStackTrace();
      ResponseResult responseResult = new ResponseResult(CommonCode.SERVER_ERROR);
      return responseResult;
    }
    @ExceptionHandler(BizException.class)
    @ResponseBody
    public ResponseResult customException(BizException e){
        log.error("catch exception : {}exception:",e.getMessage(), e);
        e.printStackTrace();
        ResponseResult responseResult = new ResponseResult(e.getResultCode());
        return responseResult;
    }
}
